#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "menu.h"
#include "operate.h"
#include "myDatatype.h"

/*主函数*/
int main(int argc, char *argv[]) 
{	
	/*建立头结点*/
	struct Node *supPhead = CreateHead();
	struct Node *comPhead = CreateHead();
	struct Node *staPhead = CreateHead();
	struct Node *masterPurPhead = CreateHead();
	struct Node *detailPurPhead = CreateHead();
	
	/*为读取文件而打开文件*/
	FILE *fpReadSup = fopen("Supplier_FILE.dat", "rb");
	FILE *fpReadCom = fopen("Commodity_FILE.dat", "rb");
	FILE *fpReadSta = fopen("Staff_FILE.dat", "rb");
	FILE *fpReadMaster = fopen("MasterPur.dat", "rb");
	FILE *fpReadDetail = fopen("DetailPur.dat", "rb");
	
	/*读取文件*/
	supPhead = ReadSup(supPhead, fpReadSup);
	comPhead = ReadCom(comPhead, fpReadCom);
	staPhead = ReadSta(staPhead, fpReadSta);
	masterPurPhead = ReadMaster(masterPurPhead, fpReadMaster);
	detailPurPhead = ReadDetail(detailPurPhead, fpReadDetail);
	
	/*将头结点放入主菜单*/
	Menu(supPhead, comPhead, staPhead, masterPurPhead, detailPurPhead);
	
	/*为写入文件而打开文件*/
	FILE *fpWriteSup = fopen("Supplier_FILE.dat", "wb");
	FILE *fpWriteCom = fopen("Commodity_FILE.dat", "wb");
	FILE *fpWriteSta = fopen("Staff_FILE.dat", "wb");
	FILE *fpWriteMaster = fopen("MasterPur.dat", "wb");
	FILE *fpWriteDetail = fopen("DetailPur.dat", "wb");
	
	/*写入文件*/
	WriteSup(supPhead, fpWriteSup);
	WriteCom(comPhead, fpWriteCom);
	WriteSta(staPhead, fpWriteSta);
	WriteMaster(masterPurPhead, fpWriteMaster);
	WriteDetail(detailPurPhead, fpWriteDetail);
	
	/*释放链表*/
	Release(supPhead);
	Release(comPhead);
	Release(staPhead);
	Release(masterPurPhead);
	Release(detailPurPhead);
	return 0;      
}